package com.sofar.gems.framework.controller;

import com.sofar.gems.framework.entity.SysRole;
import com.sofar.gems.framework.service.SysRoleService;
import com.sofar.gems.framework.service.impl.SysRoleServiceImpl;
import com.sofar.gems.framework.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 系统角色控制器
 * @company: yaorange
 * @author: 啊啊啊林
 * @version: 1.0
 * @create: 2021-09-21 18:16:27
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;


    /**
    * @description:  查询所有
    * @param
    * @return com.sofar.gems.framework.vo.R<?>
    * @exception
    */
    @GetMapping
    public R<?> selectAll() {
        List<SysRole> test = sysRoleService.findAll();
       return   R.success(test);
    }
/**
* @description:非全参 插入 新增用户
* @param sysRole
* @return com.sofar.gems.framework.vo.R<?>
* @exception
*/
    @PostMapping
    public R<?> insert(@RequestBody SysRole sysRole) {
        int i = sysRoleService.insertSelective(sysRole);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("插入失败");
        }
    }
    /**
    * @description: 通过roleid删除
    * @param roleId
    * @return com.sofar.gems.framework.vo.R<?>
    * @exception
    */
    @DeleteMapping("/{roleId}")
    public R<?> delete(@PathVariable Integer roleId ) {
        int i = sysRoleService.deleteByPrimaryKey(roleId);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("删除失败");
        }
    }

    /**
    * @description: 非全参 修改  条件修改
    * @param sysRole
    * @return com.sofar.gems.framework.vo.R<?>
    * @exception
    */
    @PutMapping
    public R<?> update(@RequestBody SysRole sysRole) {
        int i = sysRoleService.updateByPrimaryKeySelective(sysRole);
        if (i > 0) {
            return R.success("修改成功");
        } else {
            return R.error("修改失败");
        }
    }
}
